package com.erb.utils;

import java.util.Random;

/**
 * 兑换码生成类
 */
public class RedeemCodeUtils {
	// 随机类
	private static Random random = new Random();


	/**
	 * 根据所需兑换码长度生成兑换码
	 *
	 * @param codeLength 兑换码所需长度
	 * @return 兑换码字符串
	 */
	public static String generateCode(int codeLength) {
		String CODES = "23456789abcdefghjklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		StringBuilder stringBuilder = new StringBuilder();

		char[] chars = CODES.toCharArray();
		for (int i = 0; i < codeLength; i++) {
			int randomIndex = random.nextInt(CODES.length());
			stringBuilder.append(chars[randomIndex]);
		}

		return stringBuilder.toString();
	}
}
